package com.newtouch.bxzs.database.synchronize.batch.process;

import com.newtouch.bxzs.common.base.em.PublishStatusEnum;
import com.newtouch.bxzs.common.base.model.*;
import com.newtouch.bxzs.database.synchronize.model.AdvertisementBO;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;

/**
 * 处理撤销、发布状态
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/3/2 16:26</td>
 * <td>yuanjie</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class ProcesorLocalData {

    /**
     * 修改广告状态
     * @return ItemProcessor
     */
    public ItemProcessor<AdvertisementBO, AdvertisementBO> processorAdvertisement(){
        return advertisementBO -> {
            //如果状态为：未发布则修改状态为发布
                                                  if (PublishStatusEnum.UNPUBLISH_STATUS.getResultCode().equals(advertisementBO.getPublishStatus())){
                advertisementBO.setPublishStatus(PublishStatusEnum.PUBLISHED_STATUS.getResultCode());
            }else {
                //如果状态为：已发布则修改状态为已撤销
                advertisementBO.setPublishStatus(PublishStatusEnum.REVOKED_STATUS.getResultCode());
            }
            return advertisementBO;
        };
    }

    /**
     * 修改产品状态
     * @return ItemProcessor
     */
    public ItemProcessor<Product, Product> processorProduct(){
        return product -> {
            //如果状态为：未发布则修改状态为发布
            if (PublishStatusEnum.UNPUBLISH_STATUS.getResultCode().equals(product.getPublishStatus())){
                product.setPublishStatus(PublishStatusEnum.PUBLISHED_STATUS.getResultCode());
            }else {
                //如果状态为：已发布则修改状态为已撤销
                product.setPublishStatus(PublishStatusEnum.REVOKED_STATUS.getResultCode());
            }
            return product;
        };
    }

    /**
     * 修改通知状态
     * @return ItemProcessor
     */
    public ItemProcessor<Notification, Notification> processorNotification(){
        return notification -> {
            //如果状态为：未发布则修改状态为发布
            if (PublishStatusEnum.UNPUBLISH_STATUS.getResultCode().equals(notification.getPublishStatus())){
                notification.setPublishStatus(PublishStatusEnum.PUBLISHED_STATUS.getResultCode());
            }else {
                //如果状态为：已发布则修改状态为已撤销
                notification.setPublishStatus(PublishStatusEnum.REVOKED_STATUS.getResultCode());
            }
            return notification;
        };
    }

    /**
     * 修改知识小灵通状态
     * @return ItemProcessor
     */
    public ItemProcessor<KnowledgeCard, KnowledgeCard> processorKnowledgeCard(){
        return knowledgeCard -> {
            //如果状态为：未发布则修改状态为发布
            if (PublishStatusEnum.UNPUBLISH_STATUS.getResultCode().equals(knowledgeCard.getPublishStatus())){
                knowledgeCard.setPublishStatus(PublishStatusEnum.PUBLISHED_STATUS.getResultCode());
            }else {
                //如果状态为：已发布则修改状态为已撤销
                knowledgeCard.setPublishStatus(PublishStatusEnum.REVOKED_STATUS.getResultCode());
            }
            return knowledgeCard;
        };
    }

    /**
     * 修改知识库
     * @return ItemProcessor
     */
    public ItemProcessor<KnowledgeBase, KnowledgeBase> processorKnowledgeBase(){
        return knowledgeBase -> {
            //如果状态为：未发布则修改状态为发布
            if (PublishStatusEnum.UNPUBLISH_STATUS.getResultCode().equals(knowledgeBase.getPublishStatus())){
                knowledgeBase.setPublishStatus(PublishStatusEnum.PUBLISHED_STATUS.getResultCode());
            }else {
                //如果状态为：已发布则修改状态为已撤销
                knowledgeBase.setPublishStatus(PublishStatusEnum.REVOKED_STATUS.getResultCode());
            }
            return knowledgeBase;
        };
    }

    /**
     * 修改课程状态
     * @return ItemProcessor
     */
    public ItemProcessor<Course, Course> processorCourseStatus(){
        return course -> {
            //如果状态为：未发布则修改状态为发布
            if (PublishStatusEnum.UNPUBLISH_STATUS.getResultCode().equals(course.getPublishStatus())){
                course.setPublishStatus(PublishStatusEnum.PUBLISHED_STATUS.getResultCode());
            }else {
                //如果状态为：已发布则修改状态为已撤销
                course.setPublishStatus(PublishStatusEnum.REVOKED_STATUS.getResultCode());
            }
            return course;
        };
    }

    /**
     * 修改考试状态
     * @return ItemProcessor
     */
    public ItemProcessor<Examination, Examination> processorExamintionStatus(){
        return examination -> {
            //如果状态为：未发布则修改状态为发布
            if (examination.getIsEnable() == 0){
                examination.setIsEnable(1);
            }else {
                //如果状态为：已发布则修改状态为已撤销
                examination.setIsEnable(0);
            }
            return examination;
        };
    }
}
